package com.zx.server.service.impl;


import com.zx.server.dao.UserDao;
import com.zx.server.entity.IdentityEntity;
import com.zx.server.entity.UserEntity;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zx.server.service.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @auther: zhangxin
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    private  static final String INPUT="identity_queueA";

    @Autowired
    private UserService userService;

    @Autowired
    private UserDao userDao;

    @Override
    public int addUser(UserEntity userEntity) {

        int num = userDao.addUser(userEntity);
        return num;
    }

    @Override
    public int updateUser(UserEntity userEntity) {

        int num = userDao.updateUser(userEntity);
        return num;
    }

    @Override
    public List<UserEntity> getUserList(List<Integer> ids) {


        List<UserEntity> userList = userDao.getUserList(ids);
        return userList;
    }







    @RabbitListener(queues=INPUT)
    @RabbitHandler
    public void receive(IdentityEntity identity) {
        UserEntity userEntity = new UserEntity();
        userEntity.setId(identity.getId());
        userEntity.setName(identity.getRealName());
        userEntity.setIdentityStatus("已认证");
        userService.updateUser(userEntity);
    }


}
